<?php
namespace Base;

class Controller extends \Think\Controller {
	public $bridge;
	public $get;
	public $post;
	public $request;
	public $session;



	protected  function _initialize(){
		$this->get= new \Base\Request($_GET,$this);
		$this->post=new \Base\Request($_POST,$this);
		$this->request=new \Base\Request($_REQUEST,$this);
		$this->session=new \Base\Request($_SESSION,$this);
		$layoutPath='Layout/home';
		layout($layoutPath);
	}

    /**
     * 
     * 
     * @param string|Modle $name 
     * 使用模型名创建侨链
     * @return bridge
     */
	protected function dao($name=false){
		if(empty($this->bridge)) {
			$this->bridge     = new \Base\Bridge($this);
		}
		return $this->bridge->dao($name);
	}
	
    /**
     * 
     * 
     * @param string $name 
     * 使用表名创建侨链
     * @return bridge
     */
	
	protected function table($name=false){
		if(empty($this->bridge)) {
			$this->bridge     =   new \Base\Bridge($this);
		}
		return $this->bridge->table($name);
	}
	
    /**
     * 
     * 
     * @param <type> $layout 
     * 指定布局并显示
     * @return <type>
     */
	protected function layout($page='',$layout='home'){
		$layoutPath='Layout/'.strtolower($layout);
		layout($layoutPath);
		$this->display($page);
	}

	/**
	 * 返回结果
	 * @param $code
	 * @param $data
	 * @param string $type
	 */
	protected function returnResult( $code, $data,$type = '' )
	{
		$response = array(
			'code'	=>	$code,
			'data'	=>	$data,
		);
		$this->ajaxReturn( $response,$type );
	}

}